// 防抖就是重新计时
export function debounce(fn, wait) {
  let timer = null;
  return function (...args) {
    if (timer) {
      clearTimeout(timer);
    } else {
      // 如果要返回值的话，就用promise接着
      timer = setTimeout(() => {
        timer = null;
        return fn.call(this, ...args);
      }, wait);
    }
  };
}

// 节流就是比较时间
export function throolte(f, wait) {
  let currTime = new Date().getTime();

  return function () {
    let excuteTime = new Date().getTime();
    if (excuteTime - currTime > wait) {
      currTime = excuteTime;
      return fn.apply(this, arguments);
    }
  };
}
